<?php
/*
 * #116 分店分类管理 显示页面
 */
use \common\components\helpers\Fun;
use doumiaoduo\layer\LayerAsset;
LayerAsset::register($this);
?>
<style type="text/css">
.pcsorts{width:50px; text-align: center; border: 1px solid #e1e1e1}
</style>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height">
  <div class="docs-main zx-mg">
      <table  class="example-advanced table table-bordered yx-table1 yx-table4">
        <thead>
        <tr class="yx-bgdff3fe">
            <th><?=\Yii::t('zhtfrontend','编号');?></th>
            <th><?=\Yii::t('zhtfrontend','分类名称');?></th>
            <th><?=\Yii::t('zhtfrontend','pc显示');?></th>
            <th><?=\Yii::t('zhtfrontend','移动端显示');?></th>
            <th><?=\Yii::t('zhtfrontend','pc端排序');?></th>
            <th><?=\Yii::t('zhtfrontend','移动端排序');?></th>
        </tr>
        </thead>
        <tbody>
           <?=$data?>
         </tbody>

    </table>
  </div>
</div>
<input type="hidden" id="show_url" data-url="<?=Fun::url('cateattr/show')?>" value="" />
<input type="hidden" id="sort_url" data-url="<?=Fun::url('cateattr/sort')?>"  /></div>
<?php
$js = <<<JS
 layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });

     // Highlight selected row
    $(".example-advanced").on('click','tbody tr',function() {
        $(this).addClass("yx-selected").siblings().removeClass("yx-selected");
    });

   //树表格
    $(".example-advanced").treetable({expandable: true,clickableNodeNames:true,indent:19,column:1});
    $(".example-advanced").treetable("expandAll");

    // Highlight selected row
    $(".example-advanced tbody tr").mousedown(function() {
        $("tr.selected").removeClass("selected");
        $(this).addClass("selected");
    });

    //开关
   // $('input[type="checkbox"]').onoff();
    //设置隐藏显示
    $('input[type="checkbox"]').change(function(){
        var id = $(this).val();
        var field = $(this).data('field');
        var show = 0;
        var url = $('#show_url').data('url');
        if($(this).is(':checked')){
          show = 1;
        }
        $.post(url,{field:field,show:show,id:id,_csrf:yii.getCsrfToken()},function(data){
            if(data.data == 0){
                layer.msg(data.content,{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                return false;
            }
        },'json');

    });

    //修改排序
    $('td.click').dblclick(function(){
        var url = $('#sort_url').data('url');
        var field = $(this).data('field');
        var id = $(this).data('id');
        if(!$(this).is('.input')){
            $(this).addClass('input').html('<input type="text" class="pcsorts" value="'+ $(this).text() +'" />').find('input').focus().blur(function(){
                var thisid = $(this).parent().siblings("th:eq(0)").text();
                var thisvalue=$(this).val();
                var thisclass = $(this).parent().attr("class");
                if(isNaN(thisvalue)){
                  thisvalue = 0;
                }
                $.post(url,{field:field,thisvalue:thisvalue,id:id,_csrf:yii.getCsrfToken()},function(data){
                    if(data.data == 0){
                        layer.msg(data.content,{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                        return false;
                    }
                },'json');
                $(this).parent().removeClass('input').html(thisvalue);
            });
        }
    });
JS;
$this->registerJS($js);

?>